#! /bin/bash
export LANG=zh_CN.UTF-8
PRESTO_HOME=/export/server/presto/bin/presto
MYSQL_HOME=/usr/bin/mysql


echo '========================================'
echo '================开始导出================='
echo '========================================'


${MYSQL_HOME} -h192.168.88.80 -p3306 -uroot -p123456 -e "
CREATE DATABASE IF NOT EXISTS zxedu_olap DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
use zxedu_olap;
drop table IF EXISTS zxedu_olap.signup_dt_school;
DROP TABLE IF EXISTS zxedu_olap.signup_month_school;
DROP TABLE IF EXISTS zxedu_olap.signup_year_school;
DROP TABLE IF EXISTS zxedu_olap.signup_dt_origintype_school;
DROP TABLE IF EXISTS zxedu_olap.signup_mongth_origintype_school;
DROP TABLE IF EXISTS zxedu_olap.signup_year_origintype_school;
DROP TABLE IF EXISTS zxedu_olap.signup_dt_origintype_tdepart;
drop table if exists zxedu_olap.signup_month_origintype_tdepart;
drop table if exists zxedu_olap.signup_year_origintype_tdepart;
drop table if exists zxedu_olap.signup_dt_origintype_relationship;
drop table if exists zxedu_olap.signup_month_origintype_relationship;
drop table if exists zxedu_olap.signup_year_origintype_relationship;
drop table if exists zxedu_olap.signup_dt_origintype_effectiveclue;
drop table if exists zxedu_olap.signup_month_origintype_effectiveclue;
drop table if exists zxedu_olap.signup_year_origintype_effectiveclue;
"

${PRESTO_HOME} --catalog hive --server 192.168.88.80:8090 --execute "
CREATE TABLE if not exists mysql.zxedu_olap.signup_dt_school
(   dt              varchar,
    school_id       int,
    schoool_name    varchar,
    signup_count    bigint);
CREATE TABLE if not exists mysql.zxedu_olap.signup_month_school
(   mongth_code     varchar,
    school_id       int,
    schoool_name    varchar,
    signup_count    bigint);
CREATE TABLE if not exists mysql.zxedu_olap.signup_year_school
(   year_code       varchar,
    school_id       int,
    schoool_name    varchar,
    signup_count    bigint);
CREATE TABLE if not exists mysql.zxedu_olap.signup_dt_origintype_school
(   dt              varchar,
    origin_type     varchar,
    school_id       int,
    schoool_name    varchar,
    signup_count    bigint);
CREATE TABLE if not exists mysql.zxedu_olap.signup_mongth_origintype_school
(   month_code      varchar,
    origin_type     varchar,
    school_id       int,
    schoool_name    varchar,
    signup_count    bigint);
CREATE TABLE if not exists mysql.zxedu_olap.signup_year_origintype_school
(   year_code       varchar,
    origin_type     varchar,
    school_id       int,
    schoool_name    varchar,
    signup_count    bigint);
CREATE TABLE if not exists mysql.zxedu_olap.signup_dt_origintype_tdepart
(   dt              varchar,
    origin_type     varchar,
    tdepart_id      int,
    tdepart_name    varchar,
    signup_count    bigint);
CREATE TABLE if not exists mysql.zxedu_olap.signup_month_origintype_tdepart
(   month_code      varchar,
    origin_type     varchar,
    tdepart_id      int,
    tdepart_name    varchar,
    signup_count    bigint);
CREATE TABLE if not exists mysql.zxedu_olap.signup_year_origintype_tdepart
(   year_code       varchar,
    origin_type     varchar,
    tdepart_id       int,
    tdepart_name    varchar,
    signup_count    bigint);
CREATE TABLE if not exists mysql.zxedu_olap.signup_dt_origintype_relationship
(   dt                         varchar,
    origin_type                varchar,
    rate_signup_relationship   decimal(5,2));
CREATE TABLE if not exists mysql.zxedu_olap.signup_month_origintype_relationship
(   month_code                 varchar,
    origin_type                varchar,
    rate_signup_relationship   decimal(5,2));
CREATE TABLE if not exists mysql.zxedu_olap.signup_year_origintype_relationship
(   year_code                  varchar,
    origin_type                varchar,
    rate_signup_relationship   decimal(5,2));
CREATE TABLE if not exists mysql.zxedu_olap.signup_dt_origintype_effectiveclue
(   dt                          varchar,
    origin_type                 varchar,
    rate_signup_effectiveclue   decimal(5,2));
CREATE TABLE if not exists mysql.zxedu_olap.signup_month_origintype_effectiveclue
(   month_code                  varchar,
    origin_type                 varchar,
    rate_signup_effectiveclue   decimal(5,2));
CREATE TABLE if not exists mysql.zxedu_olap.signup_year_origintype_effectiveclue
(   year_code                   varchar,
    origin_type                 varchar,
    rate_signup_effectiveclue   decimal(5,2));

insert into mysql.zxedu_olap.signup_dt_school
select * from hive.zxedu_rpt.signup_dt_school;

insert into mysql.zxedu_olap.signup_month_school
select * from hive.zxedu_rpt.signup_month_school;

insert into mysql.zxedu_olap.signup_year_school
select * from hive.zxedu_rpt.signup_year_school;

insert into mysql.zxedu_olap.signup_dt_origintype_school
select * from hive.zxedu_rpt.signup_dt_origintype_school;

insert into mysql.zxedu_olap.signup_mongth_origintype_school
select * from hive.zxedu_rpt.signup_mongth_origintype_school;

insert into mysql.zxedu_olap.signup_year_origintype_school
select * from hive.zxedu_rpt.signup_year_origintype_school;

insert into mysql.zxedu_olap.signup_dt_origintype_tdepart
select * from hive.zxedu_rpt.signup_dt_origintype_tdepart;

insert into mysql.zxedu_olap.signup_month_origintype_tdepart
select * from hive.zxedu_rpt.signup_month_origintype_tdepart;

insert into mysql.zxedu_olap.signup_year_origintype_tdepart
select * from hive.zxedu_rpt.signup_year_origintype_tdepart;

insert into mysql.zxedu_olap.signup_dt_origintype_relationship
select * from hive.zxedu_rpt.signup_dt_origintype_relationship;

insert into mysql.zxedu_olap.signup_month_origintype_relationship
select * from hive.zxedu_rpt.signup_month_origintype_relationship;

insert into mysql.zxedu_olap.signup_year_origintype_relationship
select * from hive.zxedu_rpt.signup_year_origintype_relationship;

insert into mysql.zxedu_olap.signup_dt_origintype_effectiveclue
select * from hive.zxedu_rpt.signup_dt_origintype_effectiveclue;

insert into mysql.zxedu_olap.signup_month_origintype_effectiveclue
select * from hive.zxedu_rpt.signup_month_origintype_effectiveclue;

insert into mysql.zxedu_olap.signup_year_origintype_effectiveclue
select * from hive.zxedu_rpt.signup_year_origintype_effectiveclue;
"
echo '========================================'
echo '================导出结束================='
echo '========================================'